window.addEventListener("DOMContentLoaded", function() {
	// 点击回到顶部
	let toTop = document.getElementById("toTop");
	toTop.addEventListener("click", function() {
		clearInterval(this.set);
		let _this = this;
		let scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
		if(scrolltop > 0) {
			this.set = null;
			let tenth = scrolltop / 20;
			this.set = setInterval(function() {

				//document.documentElement.scrollTop -= tenth;
				window.scrollTo(0, (scrolltop - tenth));
				scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
				if(scrolltop <= 0) {
					clearInterval(_this.set);
					_this.set = null;
					return;
				}
				scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
				tenth = scrolltop / 20;
			}, 20);
			document.addEventListener("wheel" || "mousewheel", function(e) {
				clearInterval(_this.set);
				_this.set = null;
				return;
			}); // 按空格键时会出现一点bug，就是相对于多次点击回到顶部按钮，不太好
		}

	});
	window.addEventListener("scroll", function() {
		let scrolltop = document.body.scrollTop || document.documentElement.scrollTop;
		if(scrolltop > 300) {
			toTop.classList.add("showToTop");
			toTop.children[0].disabled = "";
			return;
		}
		toTop.children[0].disabled = "disabled";
		toTop.classList.remove("showToTop");
	});
});